'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 新手引导攻击方数据
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var soldierAttr = require('./soldierAttr');
var heroConf = require('../../config/heroConf');
var dataApi = require('../../libs/dataApi');
var constantUtil = require('../../util/constantUtil');
var skillAttr = require('./skillAttr');

/**
 * 获取攻击方的数据
 * @param  {[type]} copy_id [description]
 * @return {[type]}         [description]
 */
exports.getData = function (job_type) {
    var guide_conf = null;
    dataApi.guide_hero.each(function (guide_hero_conf) {
        if (guide_hero_conf.hero_type == job_type &&
            guide_hero_conf.hero_camp == 1) {
            guide_conf = guide_hero_conf;
        }
    });

    var guide_soldier_conf = dataApi.guide_soldier.findById(job_type);
    return {
        hero: _getHeroAttr(guide_conf),
        soldier_list: _getSoldierAttr(guide_soldier_conf),
    };
};

/**
 * 获取英雄数据
 */
var _getHeroAttr = function (guide_conf) {
    // 英雄类型数据
    var hero_type_conf = heroConf.getHeroTypeConf(guide_conf.hero_type);

    return {
        // 英雄职业
        hero_type: guide_conf.hero_type,

        command: guide_conf.soldier_space_num,

        // 属性
        attr: {
            // 最小攻击力
            min_atk: guide_conf.atk || 0,

            // 最大攻击力
            max_atk: guide_conf.atk || 0,

            // 血量
            hp: guide_conf.hp || 0,

            // 命中率
            hit: 100,

            // 闪避率
            dodge: 0,

            // 攻击间隔
            atk_interval: hero_type_conf.atk_interval || 0,

            // 攻击范围
            atk_range: hero_type_conf.atk_range || 0,

            // 警界范围
            warn_range: hero_type_conf.warn_range || 0,

            // 速度
            speed: hero_type_conf.speed || 0,

            // 抗性
            resistance_list: [{
                resistance_type: 1,
                resistance_value: 100
            }, {
                resistance_type: 2,
                resistance_value: 100
            }, {
                resistance_type: 3,
                resistance_value: 100
            }, {
                resistance_type: 4,
                resistance_value: 100
            }]
        },
        equip_list: _getEquipAttr(guide_conf),
        skill_list: _getSkillAttr(guide_conf),
    };
};

/**
 * 获取装备数据
 * @return {[type]} [description]
 */
var _getEquipAttr = function (guide_conf) {
    var equip_conf_list = guide_conf.equipment.split(',');
    var equip_list = [];
    _.each(equip_conf_list, function (equip_conf) {
        equip_list.push(+equip_conf);
    });
    return equip_list;
};

/**
 * 获取兵种数据
 * @return {[type]} [description]
 */
var _getSoldierAttr = function (guide_soldier_conf) {
    var soldier_data = [];
    _.each(guide_soldier_conf, function (soldier_conf_item) {
        var soldier_attr = soldierAttr.getAttr(soldier_conf_item.soldier_id, soldier_conf_item.soldier_lvl, soldier_conf_item.soldier_star);
        soldier_attr.num = 0;
        soldier_data.push(soldier_attr);
    });
    return soldier_data;
};

/**
 * 获取技能数据
 * @return {[type]} [description]
 */
var _getSkillAttr = function (guide_conf) {
    var skill_data = [];
    var skill_all_conf = guide_conf.skill.split(',');
    _.each(skill_all_conf, function (skill_conf_item) {
        var skill_conf = skill_conf_item.split(':');
        skill_data.push(skillAttr.getAttr(skill_conf[0], skill_conf[1]));
    });
    return skill_data;
};
